{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "987aca5f",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "78394f93",
   "metadata": {},
   "source": [
    "## 1. 用离差对特征列数据进行标准化\n",
    "***原理：$X'=\\frac{(X-min)}{(max-min)}$  ,离差在0~1之间***"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "35299311",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 自定义离差标准化函数\n",
    "def MinMaxScale(data):  # 形参data可以是ndarray、Series或DataFrame,\n",
    "    data_离差=(data-data.min())/(data.max()-data.min())\n",
    "    return data_离差"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a01a7edc",
   "metadata": {},
   "source": [
    "## 2. 用标准差对特征列数据进行标准化\n",
    "***原理：$X'=\\frac{(X-mean)}{std}$***"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "7e0862ef",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 自定义标准差标准化函数\n",
    "def StandardScaler(data):  # 形参可以是Series或DataFrame\n",
    "    data_标准差=(data-data.mean())/data.std()\n",
    "    return data_标准差"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b059d017",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "mining",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
